<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1">
    <title>表格</title>
    <link rel="stylesheet" href="/lib/layui-v2.5.5/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/font-awesome-4.7.0/css/font-awesome.css" media="all"/>
</head>
<body class="layui-bg-gray">
<div class="layui-container">
    <div class="layui-row">
        <div class="layui-card">
            <div class="layui-card-header"><b>修改用户</b></div>
            <div class="layui-card-body">
                <form class="layui-form layui-form-pane" >
                    <input type="hidden" name="id" required  lay-verify="required" id="id" autocomplete="off" class="layui-input">
                    <div class="layui-form-item"  pane>
                        <label class="layui-form-label">内容</label>
                        <div class="layui-input-block">
                            <input type="name" name="name" id="username" required  lay-verify="required"  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item" pane>
                        <label class="layui-form-label">路径</label>
                        <div class="layui-input-block">
                            <input type="url" name="url" id="nickname" required  lay-verify="required"  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">权限类型</label>
                        <div class="layui-input-block">
                            <select name="type" lay-verify="required">
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item" pane>
                        <label class="layui-form-label">权限表达式 </label>
                        <div class="layui-input-block">
                            <input type="permission" name="permission" id="permission" required  lay-verify="required"  autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item" pane>
                        <label class="layui-form-label">访问方式 </label>
                        <div class="layui-input-block">
                            <input type="method" name="method" id="method" required  lay-verify="required"  autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item" pane>
                        <label class="layui-form-label">排序 </label>
                        <div class="layui-input-block">
                            <input type="sort" name="sort" id="sort" required  lay-verify="required"  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item" pane>
                        <label class="layui-form-label">父级id </label>
                        <div class="layui-input-block">
                            <input type="parentId" name="parentId" id="parentId" required  lay-verify="required"  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item" >
                        <button id="edit" class="layui-btn" lay-submit lay-filter="formDemo" lay-event="edit">确定修改</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script src="/lib/layui-v2.5.5/layui.all.js" charset="utf-8"></script>
</body>
<script>
    layui.use(['form','layer'], function(){
        var form = layui.form;
        var layer=layui.layer;
        var $=layui.jquery;
        var data = layui.sessionData("mission/edit.html")["permission-id"];
        console.log(data);
        $.get("/permissions",{id:data.id},function (msg) {
            if (msg.success=="0"){
                $("input[name='id']").val(msg.data.id);
                $("input[name='name']").val(msg.data.name);
                $("input[name='url']").val(msg.data.url);
                $("input[name='type']").val(msg.data.type);
                $("input[name='permission']").val(msg.data.permission);
                $("input[name='method']").val(msg.data.method);
                $("input[name='sort']").val(msg.data.sort);
                $("input[name='parentId']").val(msg.data.parentId);
            }
        })
        //监听提交
        $.get("/select/type",{id:data.type},function (msg) {
            if(msg.success=="0"){
                var list=msg.data;
                var options="";
                for (var i in list) {
                    if (list[i].selected){options+="<option selected value='"+list[i].id+"'>"+list[i].text+"</option>";}
                    else {
                    options+="<option value='"+list[i].id+"'>"+list[i].text+"</option>";
                    }
                }
                $("[name='type']").html(options);
            }
            form.render('select');
        });


        form.on('submit(formDemo)', function(data){
            $.post("/permission",data.field,function (msg) {
                if (msg.success=='0'){
                    parent.layui.table.reload("user-tab");
                    //获取弹出窗口的id
                    var iframeIndex = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(iframeIndex);//关闭弹出窗口
                }

            })

            return false;
        });
    });

</script>
</html>